<template>
	<view class="discounts">
		<view class="tab" v-if='!totalPrices'>
			<p @click='Switcher(0)' :class="{'p':index==0}">全部<span></span></p>
			<p @click='Switcher(1)' :class="{'p':index==1}">可用<span></span></p>
			<p @click='Switcher(2)' :class="{'p':index==2}">不可用<span></span></p>
		</view>
		<discountsList v-for='value in list' :key="value.id" :obj='value' :fage='!totalPrices' :dzid='addressId' :goodsId='goodsId'>
		</discountsList>
	</view>
</template>

<script>
	import discountsList from '../../../../components/discounts_list/discounts_list.vue'
	export default {
		components: {
			discountsList
		},
		data() {
			return {
				index: 0,
				falg: false,
				totalPrices: '',
				goodsId: '',
				list: [],
				addressId: ''
			};
		},
		onLoad(res) {
			this.totalPrices = res.totalPrices
			this.goodsId = res.goods_id
			this.addressId = res.addressId
			this.getOrderCouponList(this.index);
		},
		methods: {
			Switcher(index) {
				if(this.index !== index){
					this.index = index;
					this.getOrderCouponList(this.index)
				}
			},
			getOrderCouponList(type) {
				this.$httpRequest('/coupon/getUserCouponList', {
					amount: this.totalPrices,
					goods_id: this.goodsId,
					type:type
				}).then(res => {
					this.list = res.data.data
				})
			}
		},
		// 触底刷新
		onReachBottom() {
			if (this.falg) {

			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.falg = true;
			this.list = [];
			this.getOrderCouponList(this.index);
			uni.stopPullDownRefresh();
		},
	}
</script>

<style lang="less">
	.discounts {
		&>.tab {
			width: 100%;
			height: 86rpx;
			display: flex;

			&>.p {
				color: #3B7933;

				&>span {
					background: #3B7933;
				}
			}

			&>p {
				flex: 1;
				height: 100%;
				display: flex;
				font-size: 13px;
				color: #999999;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				&>span {
					width: 28rpx;
					height: 6rpx;
					background: #3B793300;
					margin-top: 6rpx;
				}
			}
		}
	}
</style>